/* eslint-disable max-statements */ import type { MDXComponents } from 'mdx/types'; import type { GetStaticPaths, GetStaticProps } from 'next'; import dynamic from 'next/dynamic'; import Head from 'next/head'; import NextImage from 'next/image'; import Script from 'next/script'; import { useMemo, type ComponentType, type FC } from 'react'; import { useIntl } from 'react-intl'; import { Heading, Link, LoadingPage, type MetaValues, Page, PageBody, PageHeader, PageSidebar, ProjectOverview, SharingWidget, SocialLink, Spinner, Time, TocWidget, getLayout, type ProjectOverviewProps, } from '../../components'; import { mdxComponents } from '../../components/mdx'; import { fetchGithubRepoMeta } from '../../services/github'; import styles from '../../styles/pages/projects.module.scss'; import type { GithubRepositoryMeta, Maybe, NextPageWithLayout, Project, ProjectMeta, } from '../../types'; import { CONFIG } from '../../utils/config'; import { capitalize, getSchemaJson, getSinglePageSchema, getWebPageSchema, } from '../../utils/helpers'; import { type Messages, getProjectData, getProjectFilenames, loadTranslation, } from '../../utils/helpers/server'; import { useBreadcrumb, useGithubRepoMeta, useHeadingsTree, } from '../../utils/hooks'; const getGithubRepoInputFrom = (namespace: string) => { const parts = namespace.split('/'); if (parts.length !== 2) throw new Error( 'Invalid repo. It should use the following format: owner/name.' ); return { owner: parts[0], name: parts[1] }; }; const isValidRepo = (name: string): name is 'github' | 'gitlab' => ['github', 'gitlab'].includes(name); type GithubRepoOverviewProps = Omit< ProjectOverviewProps, 'cover' | 'meta' | 'name' > & Pick & { repos: { github: string; gitlab?: string; }; title: string; }; const GithubRepoOverview: FC = ({ cover, license, repos, technologies, title, ...props }) => { const intl = useIntl(); const { isLoading, meta: repoMeta } = useGithubRepoMeta( getGithubRepoInputFrom(repos.github) ); const reposLabels = { github: intl.formatMessage({ defaultMessage: 'Github', description: 'ProjectPage: Github repo label', id: 'l82UU5', }), gitlab: intl.formatMessage({ defaultMessage: 'Gitlab', description: 'ProjectPage: Gitlab repo label', id: '1msHuZ', }), }; const stars = intl.formatMessage( { defaultMessage: '{starsCount, plural, =0 {No stars} one {# star} other {# stars}}', description: 'ProjectPage: stars count', id: '4M71hp', }, { starsCount: repoMeta?.stargazerCount } ); const popularityURL = `https://github.com/${repos.github}/stargazers`; return isLoading ? ( {intl.formatMessage({ defaultMessage: 'Loading the repository metadata...', description: 'ProjectPage: loading repository metadata', id: 'EET/tC', })} ) : ( : undefined} meta={{ creationDate: repoMeta?.createdAt ? (